package com.example.killer.filemanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.killer.filemanager.MainActivity;
import com.example.killer.filemanager.R;
import com.example.killer.filemanager.util.Globals;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by killer on 2016/4/16.
 */
public class MyAdapter extends BaseAdapter {

    private Context ctx;
    private List<Map<String, Object>> values;
    public MyAdapter(Context context, List<Map<String, Object>> values) {
        this.ctx = context;
        this.values = values;
    }

    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView = LayoutInflater.from(ctx).inflate(R.layout.file_list,null);
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Globals.SCREEN_HEIGHT/8));
        }

        TextView img = (TextView) convertView.findViewById(R.id.file_img);
        TextView fileName = (TextView) convertView.findViewById(R.id.file_name);

        Map<String,Object> map = values.get(position);
        fileName.setText(map.get("fileName").toString());
        img.setBackgroundResource(Globals.imgs.get(map.get("extName")));
        img.getLayoutParams().height = Globals.SCREEN_HEIGHT/8;

        return convertView;
    }
}
